//------------------------------------------------------------------------------
//  <copyright file="KukaLBR4HardwareTests.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//  </copyright>
//------------------------------------------------------------------------------

namespace Test.Robotics.Hardware.KukaLBR.KukaLBR4Tests
{
    using System;
    using System.Runtime.InteropServices;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Test that require an operational FRI connection to a functioning KUKA LBR 4+
    /// </summary>
    [TestClass]
    [DeploymentItem("Test.Robotics.Hardware.KukaLBR.KukaLBR4NativeTestLib.dll")]
    [DeploymentItem("Microsoft.Robotics.Hardware.KukaLBR.KukaLBR4Controller.dll")]
    [DeploymentItem("Microsoft.Robotics.Manipulation.ControllerStateMachine.dll")]
    [DeploymentItem("FRI_Remote.lib")]
    public class KukaLBR4HardwareTests
    {
        /// <summary>
        /// Default size of result string
        /// </summary>
        private const int DefaultResultStringSize = 200;

        /// <summary>
        /// Test the ability to move the arm to "candle" positions (all joint positions = 0)
        /// </summary>
        [TestMethod]
        [TestCategory("Hardware")]
        [Priority(0)]
        [Timeout(60000)]
#if !KUKA_LBR_PRESENT
        [Ignore]
#endif
        public void HW_KukaLBRMoveToCandlePositionTest()
        {
            KukaLBR4UnitTests.ExecuteNativeTest(NativeMoveToCandlePositionTest, "MoveToCandlePositionTest");
        }

        /// <summary>
        /// This test is turned off as we no longer use this control method.
        /// Test the ability to move the arm to "candle" positions (all joint positions = 0)
        /// </summary>
        [TestMethod]
        [TestCategory("Hardware")]
        [Priority(0)]
        [Timeout(60000)]
        [Ignore]
        public void HW_KukaLBRMoveTestCartesian()
        {
            KukaLBR4UnitTests.ExecuteNativeTest(NativeMoveTestCartesian, "MoveTestCartesian");
        }

        /// <summary>
        /// Test that data can be received over a FRI connection.
        /// </summary>
        [TestMethod]
        [TestCategory("Hardware")]
        [Priority(0)]
        [Timeout(10000)]
#if !KUKA_LBR_PRESENT
        [Ignore]
#endif
        public void HW_KukaLBRTestFRIConnection()
        {
            KukaLBR4UnitTests.ExecuteNativeTest(NativeTestFRIConnection, "TestFRIConnection");
        }

        /// <summary> Test flooding controller running HW with new controller state machine requests.  Effect should be first and last joint rotating back and forth (in candle position) </summary>
        [TestMethod]
        [TestCategory("Hardware")]
        [Priority(0)]
        [Timeout(120000)]
#if !KUKA_LBR_PRESENT
        [Ignore]
#endif
        public void HW_KukaLBRCsmdFloodTest()
        {
            KukaLBR4UnitTests.ExecuteNativeTest(NativeCsmdFloodTest, "CsmdFloodTest");
        }

        /// <summary>
        /// Move to candle position test.
        /// </summary>
        /// <param name="resultStringPointer">A string buffer to store the test result in.</param>
        /// <param name="bufferSize">Size of the provided string buffer.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass", Justification = "Purpose of this class is to wrap PInvokes"), DllImport(
            "Test.Robotics.Hardware.KukaLBR.KukaLBR4NativeTestLib.dll",
            EntryPoint = "MoveToCandlePositionTest",
            CharSet = CharSet.Ansi,
            CallingConvention = CallingConvention.Cdecl)]
        private static extern void NativeMoveToCandlePositionTest(IntPtr resultStringPointer, int bufferSize);

        /// <summary>
        /// Move to candle position test.
        /// </summary>
        /// <param name="resultStringPointer">A string buffer to store the test result in.</param>
        /// <param name="bufferSize">Size of the provided string buffer.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass", Justification = "Purpose of this class is to wrap PInvokes"), DllImport(
            "Test.Robotics.Hardware.KukaLBR.KukaLBR4NativeTestLib.dll",
            EntryPoint = "MoveTestCartesian",
            CharSet = CharSet.Ansi,
            CallingConvention = CallingConvention.Cdecl)]
        private static extern void NativeMoveTestCartesian(IntPtr resultStringPointer, int bufferSize);

        /// <summary>
        /// Move to candle position test.
        /// </summary>
        /// <param name="resultStringPointer">A string buffer to store the test result in.</param>
        /// <param name="bufferSize">Size of the provided string buffer.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass", Justification = "Purpose of this class is to wrap PInvokes"), DllImport("Test.Robotics.Hardware.KukaLBR.KukaLBR4NativeTestLib.dll",
            EntryPoint = "TestFRIConnection",
            CharSet = CharSet.Ansi,
            CallingConvention = CallingConvention.Cdecl)]
        private static extern void NativeTestFRIConnection(IntPtr resultStringPointer, int bufferSize);

        /// <summary> Test flooding controller running HW with new controller state machine requests.  Effect should be first and last joint rotating back and forth (in candle position) </summary>
        /// <param name="resultStringPointer">A string buffer to store the test result in.</param>
        /// <param name="bufferSize">Size of the provided string buffer.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass", Justification = "Purpose of this class is to wrap PInvokes"), DllImport("Test.Robotics.Hardware.KukaLBR.KukaLBR4NativeTestLib.dll",
            EntryPoint = "CsmdFloodTest",
            CharSet = CharSet.Ansi,
            CallingConvention = CallingConvention.Cdecl)]
        private static extern void NativeCsmdFloodTest(IntPtr resultStringPointer, int bufferSize);
    }
}
